<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\MoneyLog;
use app\common\model\ScoreLog;
use app\common\model\user\Vipinfo;
use app\common\model\user\Viplists;
use app\common\model\user\Viplog;
use app\common\model\user\Viptype;
use think\Db;
use think\Exception;

class Vip extends Api
{
    protected $noNeedLogin = "*";
    protected $noNeedRight = "*";

    public function vipList()
    {
        $this->success("", Viptype::with("lists")->field("serve_discount,createtime,updatetime,is_score", true)->select());
    }

    public function vip_pay()
    {
        $id = $this->request->param("id");
        $form = $this->request->param("form");

        if (!$id || !$form) {
            $this->error("参数有误");
        }

        $vip = Viplists::get($id);
        if (!$vip) {
            $this->error("当前VIP充值信息不存在");
        }

        Db::startTrans();
        try {
            Vipinfo::buy_vip($this->auth->id, $vip, $form);
            Db::commit();
        } catch (Exception $exception) {
            Db::rollback();
            $this->error($exception->getMessage());
        }

        $this->success();
    }
}